/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.validator;

import com.minierp.bean.MessageBean;
import com.minierp.model.Message;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class MessageValidator implements Validator {
	public boolean supports(Class clazz) {
		return MessageBean.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		MessageBean bean = (MessageBean) obj;
		Message form = bean.getMessage();
		if (bean.getReceiverIdStr() != null
				&& !bean.getReceiverIdStr().equals("")) {
			if (form.getTitle() != null && !form.getTitle().equals("")) {
				if (form.getContent() != null && !form.getContent().equals("")) {
					if (form.getContent() != null
							&& form.getContent().length() > 30000) {
						errors.rejectValue("message.content", "",
								"『内容』不能超过30000个字");
					}
				} else {
					errors.rejectValue("message.content", "", "请输入『内容』");
				}
			} else {
				errors.rejectValue("message.title", "", "请输入『标题』");
			}
		} else {
			errors.rejectValue("receiverIdStr", "", "请选择『接收人』");
		}

	}
}